﻿using System.Collections.Generic;
using System.Text;
using System.Windows.Forms;

namespace BugClient
{
    public partial class ViewForm : Form
    {
        public ViewForm(JsHistorys historys, string url, string sessionID, string bugID, Dictionary<string, string> userDict, string[] actionNames, string[] stateNames, string projectName)
        {
            InitializeComponent();

            StringBuilder strb = new StringBuilder();
            if (bugID != null)
            {
                Text = "查看-" + bugID;
                
                foreach (var history in historys.historys)
                {
                    string str = history.time + " ";
                    string actor = history.user.ToString();
                    if (userDict.ContainsKey(actor))
                        actor = userDict[actor];
                    str += actor;
                    
                    str += actionNames[history.type];
                    
                    string assignee = history.assignee;
                    if (string.Empty != assignee)
                    {
                        if (history.type == (byte)eOpType.Edit)
                        {
                            str += "，优先级改为";
                        }
                        else
                        {
                            if (history.type != (byte)eOpType.Assign)
                                str += "，指派给";
                            if (userDict.ContainsKey(assignee))
                                assignee = userDict[assignee];
                        }
                        str += assignee;
                    }
                    if (!string.IsNullOrEmpty(history.comment_title))
                    {
                        if (history.type == (byte)eOpType.Create)
                        {
                            str += "，优先级";
                        }
                        else
                        {
                            if (history.type != (byte)eOpType.Comment)
                                str += "，备注：";
                            else
                                str += "：";
                            str += "\n";
                        }
                        str += history.comment_title;
                    }
                    strb.AppendLine(str);
                }
            }
            else
            {
                Text = "动态-" + projectName; ;
                
                foreach (var history in historys.historys)
                {
                    string str = history.time + " ";
                    string actor = history.user;
                    if (userDict.ContainsKey(actor))
                        actor = userDict[actor];
                    str += actor;
                    
                    if (history.type == (byte)eOpType.Assign)
                        str += "将";
                    else
                        str += actionNames[history.type];
                    
                    str += "\"" + history.comment_title + "\"";

                    string assignee = history.assignee;
                    if (string.Empty != assignee)
                    {
                        if (history.type == (byte)eOpType.Edit)
                        {
                            str += "，优先级改为";
                        }
                        else
                        {
                            if (history.type != (byte)eOpType.Assign)
                                str += "，指派给";
                            else
                                str += "指派给";
                            if (userDict.ContainsKey(assignee))
                                assignee = userDict[assignee];
                        }
                        str += assignee;
                    }
                    strb.AppendLine(str);
                }
            }
            contentBox.Text = strb.ToString();
        }
    }
}
